package com.car.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.logging.Logger;

import org.apache.commons.io.FileUtils;

import com.alibaba.common.lang.StringUtil;
import com.comm.db.SessionFactory;
import com.comm.db.pojo.RResumebasictable;
import com.comm.db.pojo.TLoginInfo;

import antlr.StringUtils;

/** 文本文件读写 */
public class TextFile {
	/*
	 * private static String basePath = "C:\\alibaba"; private static String
	 * basePath2 = "C:\\Documents and Settings\\Administrator\\桌面\\park\\sam";
	 */

	public static void main(String[] args) throws IOException {
        String encoding="Unicode";
		String filePath = "E:\\HRSystem\\test.txt";
		File file = new File(filePath);
		// FileUtils.readLines(file, encoding);
		List<String> readLinesString = FileUtils.readLines(file, encoding);

		int test = 1;
		for (String line : readLinesString) {
			if (test > 50)
				break;
			test++;
			String[] s = line.split("}");
			int count = 0;
			System.out.println(test + "---" + line);
			// 转空为0
			for (int i = 0; i < s.length; i++) {
				System.out.println(count++ + ":" + s[i]);
				if (StringUtil.isBlank(s[i])) {
					s[i] = "";
				}
			}
			try{
			RResumebasictable resumebasictable = new RResumebasictable();
			resumebasictable.setUserName(s[1]);
			resumebasictable.setBirthDay(s[2]);
			resumebasictable.setAge(StringUtil.isBlank(s[3])?null:Integer.valueOf(s[3]));
			resumebasictable.setMarried(StringUtil.isBlank(s[4])?null:Integer.valueOf(s[4]));
			resumebasictable.setExperienceTimeVal(s[5]);
			resumebasictable.setHighestDegree(s[7]);
			resumebasictable.setCurrentSalary(s[8]);
			resumebasictable.setCountry(s[11]);
			resumebasictable.setNationality(s[12]);
			resumebasictable.setLanguageName(s[27]);
			resumebasictable.setPrize(s[23]);
			resumebasictable.setCertificateName(s[25]);
			resumebasictable.setCompanyName(s[32]);
			resumebasictable.setCompanyPhone(s[14]);
			resumebasictable.setCurrentCompanyinfo(s[33]);
			resumebasictable.setDelTag(StringUtil.isBlank(s[31])?null:Integer.valueOf(s[31]));
			resumebasictable.setEmail(s[20]);
 			resumebasictable.setHobbies(s[22]);
			resumebasictable.setHomePhone(s[16]);
			resumebasictable.setIndustryName(s[26]);
			resumebasictable.setJobInterest(s[24]);
			resumebasictable.setMajorName(s[28]);
			resumebasictable.setMobile(s[15]);
 			resumebasictable.setPositionName(s[29]);
			resumebasictable.setPrize(s[23]);
			resumebasictable.setFromId(s[0]);
			resumebasictable.setWorkExperience(s[34]);
			resumebasictable.setEdu(s[35]);
			resumebasictable.setLanguageSkill(s[36]);
			resumebasictable.setItSkill(s[37]);
			resumebasictable.setProjectExperience(s[38]);
			resumebasictable.setSelfAssessment(s[39]);
			resumebasictable.setTrainer(s[40]);
			resumebasictable.setOthers(s[41]);
			}catch(Exception e){
				//错误写入  文件
				File saveFile=new File("d://error.txt");
				String oldString=FileUtils.readFileToString(saveFile, "utf-8");
				String newLine="\n";
				FileUtils.write(saveFile, oldString+newLine+line);
				e.printStackTrace();
			 
			}
		   //save(resumebasictable);
			System.out.println("----------------------" + test);
		}

	}

	static void save(RResumebasictable resumebasictable) {
		// SessionFactory.saveOrUpdate(resumebasictable);

	}
}